local xingwu = fk.CreateSkill({
  name = "kq__xingwu", 
  tags = {Skill.Compulsory},
})

xingwu:addEffect(fk.RoundStart, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xingwu.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
        room:addTableMarkIfNeed(player, "kq__xingwu_1-round", p.id)
    end
    room:addTableMark(player, "kq__xingwu_2-round")
    room:addTableMark(player, "kq__xingwu_3-round")
  end,
})

xingwu:addEffect("filter", {
  card_filter = function(self, to_select, player, is_judge)
    return to_select.suit == Card.Heart and player:hasSkill(xingwu.name) and
      (table.contains(player:getCardIds("h"), to_select.id) or is_judge) and
      player:getMark("kq__xingwu_2-round") ~= 0
  end,
  view_as = function(self, player, to_select)
    return Fk:cloneCard("analeptic", Card.Heart, to_select.number)
  end,
})

xingwu:addEffect("atkrange", {
  within_func = function (self, from, to)
    return table.contains(from:getTableMark("kq__xingwu_1-round"), to.id)
  end,
})

local spec = {
  anim_type = "masochism",
  prompt = "删去“醒恶”的一项",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xingwu.name) and player:getMark("kq__xingwu_3-round") ~= 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choice
    local yes = false
    if player:getMark("kq__xingwu_1-round") ~= 0 then

        if player:getMark("kq__xingwu_2-round") ~= 0 then

            if player:getMark("kq__xingwu_3-round") ~= 0 then
                choice = room:askToChoice(target, {
                choices = {"删去“醒恶”①" , "删去“醒恶”②" , "删去“醒恶”③", "Cancel"},
                skill_name = xingwu.name
                })
            else
                choice = room:askToChoice(target, {
                choices = {"删去“醒恶”①" , "删去“醒恶”②" , "Cancel"},
                skill_name = xingwu.name
                })
            end

        elseif player:getMark("kq__xingwu_3-round") ~= 0 then
            choice = room:askToChoice(target, {
            choices = {"删去“醒恶”①" , "删去“醒恶”③" , "Cancel"},
            skill_name = xingwu.name
            })
        else
            choice = room:askToChoice(target, {
            choices = {"删去“醒恶”①"},
            skill_name = xingwu.name
            })
        end

    elseif player:getMark("kq__xingwu_2-round") ~= 0 then
        if player:getMark("kq__xingwu_3-round") ~= 0 then
            choice = room:askToChoice(target, {
            choices = {"删去“醒恶”②" , "删去“醒恶”③" , "Cancel"},
            skill_name = xingwu.name
            })
        else
            choice = room:askToChoice(target, {
            choices = {"删去“醒恶”②", "Cancel"},
            skill_name = xingwu.name
            })
            
        end
    elseif player:getMark("kq__xingwu_3-round") ~= 0 then
        choice = room:askToChoice(target, {
            choices = {"删去“醒恶”③", "Cancel"},
            skill_name = xingwu.name
        })
        yes = true
    end
    room:addTableMark(player, "@@kq__xingwu__backspace-round")
    if choice == "删去“醒恶”①" then
        for _, p in ipairs(room:getAlivePlayers()) do
        room:setPlayerMark(p, "kq__xingwu_1-round", 0)
        end
        room:addTableMark(player, "@@kq__xingwu_s1-round")
    elseif choice == "删去“醒恶”②" then
        room:setPlayerMark(player, "kq__xingwu_2-round", 0)
        room:addTableMark(player, "@@kq__xingwu_s2-round")
    elseif choice == "删去“醒恶”③" then
        room:setPlayerMark(player, "kq__xingwu_3-round", 0)
        room:addTableMark(player, "@@kq__xingwu_s3-round")
    end

    if choice== "删去“醒恶”③"and yes == true then
        room:setPlayerMark(player, "@@kq__xingwu__backspace-round", 0)
        room:setPlayerMark(player, "@@kq__xingwu_s1-round", 0)
        room:setPlayerMark(player, "@@kq__xingwu_s2-round", 0)
        room:setPlayerMark(player, "@@kq__xingwu_s3-round", 0)
        room:handleAddLoseSkills(player, "-kq__xingwu")
        room:handleAddLoseSkills(player, "kq__botu")
        player:drawCards(1, xingwu.name)
    elseif choice== "删去“醒恶”③" and yes ~= true then
        player:drawCards(2, xingwu.name)
    else
        player:drawCards(1, xingwu.name)
    end
  end,
}

xingwu:addEffect(fk.Damage, spec)
xingwu:addEffect(fk.Damaged, spec)

Fk:loadTranslationTable {
["kq__xingwu"] = "醒恶",
[":kq__xingwu"] = "<b>锁定技</b>，①你的攻击范围包含所有角色；"..
                  "②你的<font color='red'>♥</font>手牌视为【酒】；"..
                  "③你造成或受到伤害后，本轮删去此技能一项并摸一张牌，若你为/不为最后删去此项时，你失去“<b>醒恶</b>”并获得“<b>博图<b>”/额外摸一张牌。",
["@@kq__xingwu__backspace-round"] = "已删去“醒恶”",
["@@kq__xingwu_s1-round"] = "①",
["@@kq__xingwu_s2-round"] = "②",
["@@kq__xingwu_s3-round"] = "③",
["$kq__xingwu1"] = "",
["$kq__xingwu2"] = "",
}
return xingwu